FROM quay.io/ascend/cann:8.2.rc1.alpha002-910b-openeuler22.03-py3.10

# 设置环境变量
ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest \
    LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64/stub:/usr/local/Ascend/ascend-toolkit/latest/lib64:/usr/local/Ascend/add-ons:$LD_LIBRARY_PATH

# 安装系统依赖
RUN yum update -y && \
    yum install -y \
    git \
    wget \
    vim \
    gcc \
    gcc-c++ \
    make \
    cmake \
    unzip \
    libglvnd-glx \
    mesa-libGL \
    libX11 \
    libXext \
    libXrender \
    && yum clean all

WORKDIR /app

# 设置 Python 镜像源
RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

# 安装 PyTorch 和 torch_npu (适配 CANN 8.0+)
# 使用 2.1.0 版本以确保与 CANN 8.2 的兼容性
RUN pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0
RUN pip install torch-npu==2.1.0

# 安装项目依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 确保 numpy 版本兼容 torch（其他包可能升级 numpy 到 2.x）
RUN pip install --no-cache-dir "numpy<2.0.0"

# 复制项目代码
COPY api/ /app/api/
COPY config/ /app/config/

# 设置环境变量
ENV PYTHONPATH=/app:$PYTHONPATH
ENV ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/latest/opp

# 暴露端口
EXPOSE 8000

# 启动命令
CMD ["python3", "api/main.py"]

